﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo3
{
    struct Time
    {
        public int h;
        public int m;
    }
    class Clock
    {
        private static int hour = 0;
        private static int minute = 0;
        private static int second = 0;
        static List<Time> alarmlist = new List<Time>();
        public delegate void alarmhandler();
        public event alarmhandler alarm;
        public delegate void tickhandler();
        public event tickhandler tick;
        public void isalarm()
        {
            Time temp = new Time();
            for (int i = 0; i < alarmlist.Count; i++)
            {
                temp = alarmlist[i];
                if (hour == temp.h || minute == temp.m)
                {
                    alarm();
                }
            }
        }
        public void setalarm(int hour,int minute)
        {
            Time onetime = new Time();
            onetime.h = hour;
            onetime.h = minute;
            alarmlist.Add(onetime);
        }
        public void setfirsttime(int h,int m)
        {
            hour = h;
            minute = m;
        }
        //配合线程实现时钟自增
        public void add()
        {   //时钟规则
            second++;
            if(second == 60)
            {
                minute++;
                tick();
            }
            if (minute == 60)
            {
                hour++;
            }
            if(hour == 24)
            {
                hour = 0;
            }
        }

        
    }
}
